#!/usr/bin/env python
# _*_ coding:utf-8 _*_
# 需要在yaml中调用的函数在此添加后可以实现函数热加载，通过函数进行参数化
import time
import urllib.parse
from commons.databases import db
from commons.files import YamlFile
import logging
logger = logging.getLogger(__name__)


def url_unquote(s: str) -> str:
    return urllib.parse.unquote(s)


def time_str():
    return str(int(time.time()))  # 用于生成随机数


def sql(s: str) -> str:
    try:
        res = db.execute_sql(s)  # 执行sql
        return res[0]
    except TypeError:
        print("res is None")


def new_id():
    # 自增，不重复
    id_file = YamlFile("id.yaml")
    id_file["id"] += 1

    id_file.save()

    return id_file["id"]